<template>
  <view>
    <img src="../../static/images/bg_time.jpg" class="bg_time">
    <view class="sign_page">

      <view class="sign_web">
        <img src="/static/logo.svg" alt="" class="logoImg">
        <span style="text-align: center;font-size: 46rpx;margin-left: 15rpx;">励氪签</span>
      </view>

      <view class="padding_vw">
        <uni-card>
          <h3>{{ form.contractName }}</h3>
          <p>发起方：{{ companyName[0] }}<br/>接收方：{{ form.signCompany }}</p>
          <p class="line-p">合同发起时间：{{ form.createTime }}<br/>签署截止时间：{{ form.signExpiryDate }}</p>
          <view class="time_count">
            <span>剩余</span>
            <uni-countdown :font-size="19" :second="second" splitorColor="#00a660" color="#00a660" background-color="#fff"/>
            <span>截止签约</span>
          </view>
        </uni-card>
      </view>
      <uni-notice-bar color="#00a660" background-color="#e6f6ef" text="请登录电子签约平台，查看并签署文件" />
      <!--验证码或者密码登录框-->
      <loginPassWordOrSMS :mobile="form.signerMobile" @loginOk="loginOk"></loginPassWordOrSMS>
    </view>
  </view>
</template>

<script>
	import {changeUser,} from "../../api/login";
	import {getContractSignMineByRsa} from "../../api/contractSign";
	import {getSecondNowDiff} from "../../utils/ruoyi";
	import {paramString2Obj} from "../../utils/common";
	import Base64 from "../../utils/base64";
	import {updateSession} from "../../api/userInfo";
  import {getCompany} from "../../api/ec/work/company/company";
  import loginPassWordOrSMS from "./loginPassWordOrSMS";
	export default {
		components: {
			loginPassWordOrSMS
		},
		data() {
			return {
				id: "", //合同id
				flowId: "", //流程id
				form: {}, //
				second: 0, //
				companyName: '',
			}
		},
		onLoad(options) {
      this.$modal.loading();
			let share = atob(decodeURI(options.share));
			let param2Obj = paramString2Obj(share);
			this.id = param2Obj.id;
			this.flowId = param2Obj.flowId;
			// 根据签署流程id 查询
			getContractSignMineByRsa(Base64.encode(this.flowId)).then((response) => {
				this.form = JSON.parse(Base64.decode(response.data.split("").reverse().join("")));
				let str_split = this.form.signCompanyAllName.split('；');
				this.companyName = str_split
				// 计算签署日期距离现在还有多久
				this.second = getSecondNowDiff(this.form.signExpiryDate)
        this.$modal.closeLoading()
			});
		},
		created() {

		},
		methods: {
      getSMSCode(type) {
        // 获取验证码
        this.getCode(this.form.signerMobile,type);
      },
			/** 接受子组件传过来的值点击切换导航 */
			tabtap(index) {
        this.tabIndex = index;
			},
      async loginOk() {
        this.$store.dispatch('GetInfo').then(async res => {
          // 个人未认证状态 跳转到页面
          if (res.user.isCertify == 0) {
            this.$tab.reLaunch("/pages/authentication/personal/personal?signTask=1");
            return;
          }
          this.$modal.closeLoading();
          // this.form.systemCompanyId 这个公司是否实名认证  若没有实名认证 跳转到实名认证中
          if (this.form.systemCompanyId != 0) {
            let companyIsCert;
            // 查询公司信息
            await getCompany(this.form.systemCompanyId).then(res => {
              companyIsCert = res.data.isCertify;
            })
            // 若公司没有认证 则跳转到公司认证页面
            if (companyIsCert == 0) {
              this.$tab.reLaunch("/pages/authentication/companyRealname/start?id=" + this.form.systemCompanyId+"&signTask=0")
              return;
            }
          }
          if (res.user.companyId != this.form.systemCompanyId) {
            changeUser(this.form.systemCompanyId == 0 ? null : this.form.systemCompanyId).then(() => {
              updateSession().then((response) => {
                this.$store.dispatch('GetInfo').then((res) => {
                  this.$tab.reLaunch(`/pages/sign/signedByme?id=${this.id}&flowId=${this.flowId}`)
                });
              });
            });
            return;
          }
          await this.$tab.reLaunch(`/pages/sign/signedByme?id=${this.id}&flowId=${this.flowId}`)
        })
      }
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-noticebar{
		justify-content: center;
		text-align: center;
	}

	page {
		background-color: $uni-bg-color;
	}

	.sms-input ::v-deep.is-input-border {
		background: #f5f6f7 !important;
		width: 95%;
		border: none;
		padding-left: 14rpx;
	}

	.easyinput {
		width: 100%;
	}

	::v-deep .uni-card {
		box-shadow: rgba(225, 225, 225, 0.1) 0px 0px 2px 1px !important;
		// margin: 20rpx 30rpx !important;
	}

	.bg_time {
		width: 100%;
		height: 100%;
	}

	.bot_top {
		margin: 0 30rpx;
	}

	.time_count {
		margin: 40rpx 0 20rpx;
		display: flex;
		align-items: center;
		width: 100%;
		text-align: center;
		color: #00a660;
		justify-content: center;

		span {
			margin: 0 10rpx;
			font-size: 26rpx
		}

		::v-deep .uni-countdown__number {
			border: 1rpx solid #00a660;
			border-radius: 2px;
		}
	}

	.padding_vw {
		margin-top: 20rpx;

		h3 {
			margin-top: 25rpx;
			font-weight: normal;
			color: #666666;
		}

		p {
			margin: 30rpx 0;
			color: #7a7a7a;
		}

		.line-p {
			padding: 0 0 35rpx;
			border-bottom: 1rpx solid #e5e5e5;

			span {
				margin-left: 16rpx;
			}
		}
	}

	.sign_web {
		.logoImg {
			width: 70rpx;
			height: 70rpx;
		}
		display: flex;
		align-items: center;
		margin: 0 auto;
		justify-content: center;
		width: 100%;
	}

	.sign_page {
		position: absolute;
		top: 5%;
		width: 100%;
	}
</style>
